<html>
   <head>
      <title>Paired polynomial fit of closing prices</title>
   </head>
   <body>
      <table>
         <tr>
            <g:form>
            <td>
                    <g:select name="select1" from="${['DIA', 'SPY', 'GLD']}" value="${params.select1}"/>
            </td> 
            <td>
                    <g:select name="select2" from="${['DIA', 'SPY', 'GLD']}" value="${params.select2}"/>
            </td>
            <td>
                    Power <g:select name="power" from="${[1, 2, 3, 4]}" value="${params.power}"></g:select>
            </td>
            <td>
               <g:actionSubmit name="doChart" action="index" value="Chart"/>
            </td>
            </g:form></td>
         </tr>
      </table>
      
      <g:if test="${params.select1 != null}">
        <p>&nbsp; &nbsp;EOD Close ${params.select1} vs ${params.select2}</p>
        <p>&nbsp; &nbsp;y = ${polynomial}</p>
        
        <table border="1">
           <tr>
               <g:each in="${corrParams}" var="entry" >
                      <td>${entry.key}</td>
                    </g:each>
           </tr>
           <tr>
               <g:each in="${corrParams}" var="entry" >
               <g:each in="${entry.value}" var="item" >
                      <td>${sprintf('%.3g', item)}</td>
                    </g:each>
              </g:each>
           </tr>
        </table>
        
        <br/>
        
            <%
               def dataMax = data?.values()?.max()
               def fitDataMax = fitData?.values()?.max()
               def yMax = Math.max(dataMax, fitDataMax)
               def priceData = [data?.values()?.asList(), 
                   fitData?.values()?.asList()]
            %>
            <g:lineChart type="lc" 
                size="${[600,200]}" 
                colors="${['FF0000','0000FF']}" 
                axes="x,y" 
                lineStyles="${[[2,2,2],[2,8,4]]}" 
                legend="${['Data', 'Fit']}" 
                gridLines="${dataMax/11},25" 
                axesLabels="${[0:xLabels,1:[0,yMax/2,yMax]] }"
                data="${priceData}"
                dataType="simple"/>
                
            <br/>
                
        <table border="1">
           <tr>
               <td align="center" colspan="${stats[0].size() + 1}">
                   Relative error fit statitics
               </td>
           </tr>
           <tr>
               <td>Added Noise % of variance</td>
               <g:each in="${stats[0]}" var="entry" >
                     <td>${entry.key}</td>
                    </g:each>
           </tr>
           
           <g:each in="${0..< stats.size()}" }>
           <tr align="center">
                   <td>${ 2 ** it } %</td>
               <g:each in="${stats[it]}" var="entry" >
               <g:each in="${entry.value}" var="item" >
                      <td>${sprintf('%.3g', item)}</td>
                    </g:each>
                       </g:each>
           </tr>
      </g:each>
        </table>
        <br/>
        </g:if>
    </body>
</html>